package com.ruoyi.bysj.controller;

import com.ruoyi.bysj.domain.SysDelivery;
import com.ruoyi.bysj.domain.SysGoods;
import com.ruoyi.bysj.service.ISysDeliveryService;
import com.ruoyi.bysj.service.ISysGoodsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 货物配送Controller
 * 
 * @author laow
 * @date 2021-10-19
 */
@RestController
@RequestMapping("/bysj/storekeeper")
public class SysStorekeeperController extends BaseController
{
    @Autowired
    private ISysDeliveryService sysDeliveryService;

    @Autowired
    private ISysGoodsService sysGoodsService;

    /**
     * 查询货物配送列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:storekeeper:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDelivery sysDelivery)
    {
        startPage();
        List<SysDelivery> list = sysDeliveryService.selectSysDeliveryList(sysDelivery);
        return getDataTable(list);
    }


    /**
     * 获取货物配送详细信息
     */
    @PreAuthorize("@ss.hasPermi('bysj:storekeeper:query')")
    @GetMapping(value =    "/{deliveryId}"  )
    public AjaxResult getInfo(@PathVariable("deliveryId") Long deliveryId)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("goods", sysGoodsService.selectGoodsAll());
        if (StringUtils.isNotNull(deliveryId))
        {
            ajax.put(AjaxResult.DATA_TAG, sysDeliveryService.selectSysDeliveryByDeliveryId(deliveryId));
            ajax.put("goodsIds", sysDeliveryService.selectGoodsListBydeliveryId(deliveryId));
        }
        return ajax;
    }

    /**
     * 修改货物配送
     */
    @PreAuthorize("@ss.hasPermi('bysj:storekeeper:edit')")
    @Log(title = "货物配送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDelivery sysDelivery)
    {
        sysDelivery.setDeliveryName(getUsername());
        return toAjax(sysDeliveryService.updateSysDelivery(sysDelivery));
    }

    /**
     * 查询仓库存储列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:storekeeper:goodsList')")
    @GetMapping("/goodsList")
    public TableDataInfo goodsList(SysGoods sysGoods)
    {
        List<SysGoods> list = sysGoodsService.selectSysGoodsList(sysGoods);
        return getDataTable(list);
    }

    /**
     * 获取货物配送详细信息
     */
    @PreAuthorize("@ss.hasPermi('bysj:storekeeper:goodsQuery')")
    @GetMapping(value =    "/goods/{deliveryId}"  )
    public TableDataInfo goodsList2(@PathVariable("deliveryId") Long deliveryId)
    {
        List<SysGoods> list = sysDeliveryService.selectGoodsListsBydeliveryId(deliveryId);
        return getDataTable(list);
    }
}
